﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Team4Mock.Entity;
namespace Team4Mock.FormView
{
    public partial class Login : System.Web.UI.Page
    {
        UserEntity ue = new UserEntity();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                user.Focus();
                lbname.Text = "<b>Password</b>";
                btn.Visible = true;
                btnSend.Visible = false;
                pass.Visible = true;
                email.Visible = false;
            }
            
        }

        protected void btn_Click(object sender, EventArgs e)
        {
            if (user.Text == "" || pass.Text == "")
                tb.Text = "Input Username and Password";
            else
            {
                ue.ACCOUNT = user.Text.Trim();
                ue.PASSWORD = pass.Text.Trim();
                if (ue.CheckLogin(ue) == true)
                {
                    Session["user"] = user.Text.Trim();
                    Session.Timeout = 60;
                    Session["role"] = ue.GetRole(ue);
                    Response.Redirect("/FormView/Default.aspx");
                }
                else
                    tb.Text = "Username or Password do not match";
            }
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("/FormView/Default.aspx");
        }

        protected void Linkforgot_Click(object sender, EventArgs e)
        {
            lbname.Text = "<b>Email</b>";
            btn.Visible = false;
            btnSend.Visible = true;
            pass.Visible = false;
            email.Visible = true;
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            ue.ACCOUNT = user.Text.Trim();
            ue.EMAIL = email.Text.Trim();
            if (ue.CheckEmail(ue) == true)
            {
                //if (ue.SendMail_Thankyou(ue) == true)
                    tb.Text = "Password sent to the email address " + email.Text.Trim();
                //else
                    //tb.Text = "Error";
            }
            else tb.Text = "Email not valid";
        }
    }
}